package com.wang.concurrency;

public class Depositor {

	
	public static void main(String[] args) {
		Account2 a = new Account2();

			new Thread(new Draw(a, 100.0),"取钱者").start();;
			new Thread(new Deposit(a, 100),"存钱者").start();;

				
		
	}
	
	
	private static class Draw implements Runnable{
		
		
		private Account2 account;
		private double amount;
		
		
		public Draw(Account2 account, double amount) {
			super();
			this.account = account;
			this.amount = amount;
		}


		@Override
		public void run() {
			try {
				account.draw(amount);
				Thread.sleep(500);
			} catch (InterruptedException e) {		
				e.printStackTrace();
			}						
		}
		
	}
	
	
	
	private static class Deposit implements Runnable{
		
		private Account2 account;
		private double amount;
		
		public Deposit(Account2 account, double amount) {
			super();
			this.account = account;
			this.amount = amount;
		}
		@Override
		public void run() {
			try {
				account.deposit(amount);
				Thread.sleep(500);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}			
		}
		
	}
	
}
